<template>
	<div id="playerView" >
		<!-- 背景 -->
		<div class="mask" :style="{'background-image':`url(${albumPic})`}" ></div>
		
		<div>
			
			<!-- 头部 -->
			<div class="header">
				<div class="hideBtn" @click="togglePlayer">
					<i class="iconfont icon-xiangxiajiantou"></i>
				</div>
				<div class="title">
            <p class="songname">{{songdata.name}}</p>
            <p><span class="artist" v-for="(art,index) in songdata.artist" :key="index"><span v-if="index!==0"> / </span>{{art.name}}</span></p>
        </div>
			</div>
			<!-- 唱片/歌词 -->
			<div>
				<!-- 唱片 -->
				<div class="disc" :class="{active:isPlaying}" >

					<img class="cover" :src="albumPic" >
					<img src="../images/disc-ip6.png" >
				</div>

				<!-- 歌词 -->
				<div class="lyric"></div>

			</div>

			<!--进度条-->
			<div class="progress">
				
				<div class="time">{{secToMin(currentTime)}}</div>
				<kprogress :present="present" @progressChange="pChange"></kprogress>
				<div class="time">{{secToMin(totalTime)}}</div>
				
			</div>

			<!--控制器-->
			<div class="contorl">
				<div class="prevBtn fl" @click="playBtnEvent('-')">
					<i class="iconfont icon-shangyishou"></i>
				</div>
				<div class="playBtn" @click="playBtnEvent()" >
					<i class="iconfont" :class="isPlaying? 'icon-zanting':'icon-play' " ></i>
				</div>
				<div class="nextBtn fr" @click="playBtnEvent('+')">
					<i class="iconfont icon-xiayishou"></i>
				</div>
			</div>

		</div>

	</div>
</template>

<script>
import kprogress from "./progress.vue";

export default {
    props:["songdata"],
    data() {
        return {
            lrc:false,
        };
    },
    methods: {
        togglePlayer() {
            this.$emit("show-pv",false)
        },
        /**
         * 	转换歌曲时长的函数
         */
        secToMin(time) {
        var min = Math.floor(time / 60),
            second = time % 60,
            hour,
            newMin;

        if (min > 60) {
            hour = Math.floor(min / 60);
            newMin = min % 60;
        }

        if (second < 10) {
            second = "0" + parseInt(second);
        } else {
            second = parseInt(second);
        }
        if (min < 10) {
            min = "0" + min;
        }

        return hour ? hour + ":" + newMin + ":" + second : min + ":" + second;
        },

        playBtnEvent(type="playOrPause") {
          this.$emit("btns",type)
        },
        /**
         * 进度条组件拖动后的触发的事件
         * 根据百分比计算，改变播放器的当前时间
         * */

        pChange(e) {
          this.$parent.player.currentTime = e * this.$parent.player.duration;
        },
    },
    computed: {
        isPlaying: function() {
          return this.$store.state.playerState =="play";
        },
        currentTime: function(){
          return this.$store.state.currentTime ;
        },
        totalTime: function(){
          return this.$store.state.totalTime ;
        },
        present(){
          return (this.currentTime/this.totalTime)*100;
        },
        albumPic(){
            return this.$store.state.albumPic;
        }
    },
    components: {
        kprogress
    },
    updated(){
          // console.log("computed",this.$store.state.playerState);
    }
};
</script>

<style lang="scss">
#playerView {
  position: absolute;
  z-index: 100;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #222;
  color: #fff;
  overflow: hidden;
  .mask {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    -webkit-filter: blur(15px) brightness(70%); /* Chrome, Safari, Opera */
    filter: blur(15px) brightness(70%);
  }
  .header {
    position: absolute;
    top: 0;
    height: 50px;

    div {
      display: inline-block;
      text-align: center;
      vertical-align: top;
    }
    .hideBtn {
      width: 20vw;
      line-height: 50px;
    }
    .title {
      padding-top: 10px;
      width: 60vw;
      font-size: 16px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      .songname{
        font-size: 18px;
        line-height: 1.4;
      }
      .artist{
        font-size: 12px;
      }
    }
  }
  .disc {
    position: absolute;
    top: 18vh;
    left: 50%;
    margin-left: -40vw;
    width: 80vw;
    height: 80vw;
    overflow: hidden;
    border-radius: 50%;
    background-size: 70%;
    background-position: center;
    background-repeat: no-repeat;
    animation: rotation 20s infinite linear;
    animation-play-state: paused;
    img {
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
    }
    .cover {
      width: 70%;
      height: 70%;
      left: 15%;
      top: 15%;
      border-radius: 50%;
    }
    &.active {
    animation-play-state: running;
    }
  }
  .progress {
    position: absolute;
    left: 2vw;
    right: 2vw;
    bottom: 18vh;
    margin-top: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    .k-progress {
      width: 65%;
      margin: 0 2.5%;
    }
  }
  .time{
    padding: 0 4px;
  }
  .contorl {
    position: absolute;
    bottom: 5vh;
    left: 20vw;
    width: 60vw;
    height: 10vh;
    line-height: 10vh;
    text-align: center;
    div {
      display: inline-block;
    }
    .playBtn {
      i {
        font-size: 50px;
      }
    }
    .prevBtn,
    .nextBtn {
      i {
        font-size: 40px;
      }
    }
  }
}
@keyframes rotation {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>